/*! \file block_header.inl
 *	\brief 
 *
 *	created:	2009/11/20
 *	created:	20:11:2009   18:24
 *	filename: 	o:\main\libs\mem\impl\block_header.inl
 *	file path:	o:\main\libs\mem\impl
 *	file base:	block_header
 *	file ext:	inl
 *	author:		Vitalii Trubchaninov
 *				venngraydog@gmail.com
 */

#include "routines.h"

namespace tt{
namespace mem{
namespace impl{

inline
BlockHeader* to_block_header(void* mem)
{
	return reinterpret_cast<BlockHeader*>(reinterpret_cast<char*>(mem) - BLOCK_HEADER_SIZE);
}

inline
void* to_memory(BlockHeader* block)
{
	return reinterpret_cast<char*>(block) + BLOCK_HEADER_SIZE;
}

//////////////////////////////////////////////////////////////////////////
template<BlockType block_type>
BlockHeader* block_new( std::size_t size)
{
	BlockHeader* bh = reinterpret_cast<BlockHeader*>( mgt_malloc(size + BLOCK_HEADER_SIZE) );
	bh->size = size;
	bh->block_type = block_type;
	return bh;
}

template<BlockType block_type>
void block_delete(BlockHeader* block)
{
	mgt_free(block);
}

} //impl
} //mem
} //namespace tt
